PERMANOVA for single polyp metabolomics

libraries

## Warning: package 'ape' was built under R version 3.6.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Warning: package 'ggplot2' was built under R version 3.6.2
## Warning: package 'ggpubr' was built under R version 3.6.2
## 
## Attaching package: 'ggpubr'
## The following object is masked from 'package:plyr':
## 
##     mutate
## The following object is masked from 'package:ape':
## 
##     rotate
## Warning: package 'lmerTest' was built under R version 3.6.2
## Loading required package: lme4
## Warning: package 'lme4' was built under R version 3.6.2
## Loading required package: Matrix
## Warning: package 'Matrix' was built under R version 3.6.2
## Registered S3 methods overwritten by 'lme4':
##   method                          from
##   cooks.distance.influence.merMod car 
##   influence.merMod                car 
##   dfbeta.influence.merMod         car 
##   dfbetas.influence.merMod        car
## 
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
## Warning: package 'car' was built under R version 3.6.2
## Loading required package: carData
## Warning: package 'carData' was built under R version 3.6.2
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
## Warning: package 'emmeans' was built under R version 3.6.2
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
## Warning: package 'multcomp' was built under R version 3.6.2
## Loading required package: mvtnorm
## Warning: package 'mvtnorm' was built under R version 3.6.2
## Loading required package: survival
## Warning: package 'survival' was built under R version 3.6.2
## Loading required package: TH.data
## Loading required package: MASS
## Warning: package 'MASS' was built under R version 3.6.2
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
## 
## Attaching package: 'TH.data'
## The following object is masked from 'package:MASS':
## 
##     geyser
## 
## Attaching package: 'reshape'
## The following object is masked from 'package:Matrix':
## 
##     expand
## The following object is masked from 'package:dplyr':
## 
##     rename
## The following objects are masked from 'package:plyr':
## 
##     rename, round_any
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ tibble  3.1.0     ✓ purrr   0.3.4
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.1
## Warning: package 'readr' was built under R version 3.6.2
## Warning: package 'purrr' was built under R version 3.6.2
## Warning: package 'forcats' was built under R version 3.6.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::arrange()     masks plyr::arrange()
## x gridExtra::combine() masks dplyr::combine()
## x purrr::compact()     masks plyr::compact()
## x dplyr::count()       masks plyr::count()
## x tidyr::expand()      masks reshape::expand(), Matrix::expand()
## x dplyr::failwith()    masks plyr::failwith()
## x dplyr::filter()      masks stats::filter()
## x dplyr::id()          masks plyr::id()
## x dplyr::lag()         masks stats::lag()
## x ggpubr::mutate()     masks dplyr::mutate(), plyr::mutate()
## x tidyr::pack()        masks Matrix::pack()
## x car::recode()        masks dplyr::recode()
## x reshape::rename()    masks dplyr::rename(), plyr::rename()
## x MASS::select()       masks dplyr::select()
## x purrr::some()        masks car::some()
## x dplyr::summarise()   masks plyr::summarise()
## x dplyr::summarize()   masks plyr::summarize()
## x tidyr::unpack()      masks Matrix::unpack()
## Warning: package 'factoextra' was built under R version 3.6.2
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
## Warning: package 'reshape2' was built under R version 3.6.2
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
## The following objects are masked from 'package:reshape':
## 
##     colsplit, melt, recast
## Warning: package 'vegan' was built under R version 3.6.2
## Loading required package: permute
## Loading required package: lattice
## Warning: package 'lattice' was built under R version 3.6.2
## This is vegan 2.5-7
## Loading required package: cluster
## Warning: package 'cluster' was built under R version 3.6.2
## Warning: package 'scales' was built under R version 3.6.2
## 
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
## 
##     discard
## The following object is masked from 'package:readr':
## 
##     col_factor
## [1] '1.1.1'
## Warning: package 'devtools' was built under R version 3.6.2
## Loading required package: usethis
## Warning: package 'usethis' was built under R version 3.6.2
## 
## Attaching package: 'devtools'
## The following object is masked from 'package:permute':
## 
##     check
## The following object is masked from 'package:emmeans':
## 
##     test
## 
## microbiome R package (microbiome.github.com)
##     
## 
## 
##  Copyright (C) 2011-2021 Leo Lahti, 
##     Sudarshan Shetty et al. <microbiome.github.io>
## 
## Attaching package: 'microbiome'
## The following object is masked from 'package:scales':
## 
##     alpha
## The following object is masked from 'package:vegan':
## 
##     diversity
## The following object is masked from 'package:ggplot2':
## 
##     alpha
## The following object is masked from 'package:base':
## 
##     transform

Load in data:

mData<-read.csv("single polyp master with PCoA coordinates.csv") #metabolomics data and xy coords from Ty
mData$ATTRIBUTE_Sample_Name<-as.factor(as.character(mData$ATTRIBUTE_Sample_Name))
mData$ATTRIBUTE_Colony_number<-as.factor(as.character(mData$ATTRIBUTE_Colony_number))
mData<-subset(mData, ATTRIBUTE_Colony_number!="976B")

PERMANOVA

#PERMANOVA

#sep dfs
mData.sd<-mData[,1:11] #metadata
mData.meta<-mData[,12:566] #metabolomics data
# mData.PCoA<-mData[,567:568] #ty's x and y, but can't use these for STATS
# plot(mData.PCoA) #plot Ty's x and y, to confirm your distance matrix cooresponds right


####################### Between colonies and Between Sample points


# Bray-Curtis distance 
mData.dist <- vegdist(mData[,12:566],  method = "bray")
# write.csv(mData.dist, "mData.dist.csv")

PCOA <- pcoa(mData.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

mData.dist2<-as.matrix(mData.dist)

 mData.dist.sd<- inner_join(rownames_to_column(mData.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata

############ plot Between colonies 

BetweenColonies_plot<-ggplot(mData.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Colony_number), size = 4) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Colonies") +
  theme_classic();BetweenColonies_plot

#PERMANOVA between COLONIES
set.seed(30)
adonis(mData.dist~ATTRIBUTE_Colony_number, data=mData.sd)
## 
## Call:
## adonis(formula = mData.dist ~ ATTRIBUTE_Colony_number, data = mData.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                          Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)    
## ATTRIBUTE_Colony_number  18    18.732 1.04064  32.641 0.64527  0.001 ***
## Residuals               323    10.297 0.03188         0.35473           
## Total                   341    29.029                 1.00000           
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#                          Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)   
# ATTRIBUTE_Colony_number  18    18.732 1.04064  32.641 0.64527  0.001 ***
# Residuals               323    10.297 0.03188         0.35473           
# Total                   341    29.029                 1.00000     



############# Between Sampling areas (polyps) ########
set.seed(30)
adonis(mData.dist~Area, data=mData.sd)
## 
## Call:
## adonis(formula = mData.dist ~ Area, data = mData.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)  
## Area        5    0.7291 0.145811  1.7312 0.02511  0.017 *
## Residuals 336   28.3000 0.084226         0.97489         
## Total     341   29.0290                  1.00000         
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)  
# Area        5    0.7291 0.145811  1.7312 0.02511  0.017 *
# Residuals 336   28.3000 0.084226         0.97489         
# Total     341   29.0290                  1.00000    

adonis(mData.dist~Area*ATTRIBUTE_Colony_number, data=mData.sd)
## 
## Call:
## adonis(formula = mData.dist ~ Area * ATTRIBUTE_Colony_number,      data = mData.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                               Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)    
## Area                           5    0.7291 0.14581   4.864 0.02511  0.001 ***
## ATTRIBUTE_Colony_number       18   18.7315 1.04064  34.712 0.64527  0.001 ***
## Area:ATTRIBUTE_Colony_number  90    2.7332 0.03037   1.013 0.09415  0.442    
## Residuals                    228    6.8353 0.02998         0.23546           
## Total                        341   29.0290                 1.00000           
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#                               Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)    
# Area                           5    0.7291 0.14581   4.864 0.02511  0.001 ***
# ATTRIBUTE_Colony_number       18   18.7315 1.04064  34.712 0.64527  0.001 ***
# Area:ATTRIBUTE_Colony_number  90    2.7332 0.03037   1.013 0.09415  0.445    
# Residuals                    228    6.8353 0.02998         0.23546           
# Total                        341   29.0290                 1.00000           

#Plot: No patterns
BetweenSampArea_plot<-ggplot(mData.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = Area), size = 4) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Sampling Area") +
  theme_classic();BetweenSampArea_plot

Between polyps 1-3 only

# ########################### Between polyps 1-3 only
#subset data
mData.Polyps123<-subset(mData, Area=="Base"|Area=="Touching 1"|Area=="Touching 2")
mData.Polyps123.sd<-mData.Polyps123[,1:11]
# Bray-Curtis distance 
mData.Polyps123.dist <- vegdist(mData.Polyps123[,12:566],  method = "bray")

PCOA <- pcoa(mData.Polyps123.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Polyps123.dist.sd<- inner_join(rownames_to_column(mData.Polyps123.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Polyps123.dist~Area, data=mData.Polyps123.sd)
## 
## Call:
## adonis(formula = mData.Polyps123.dist ~ Area, data = mData.Polyps123.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
## Area        2    0.0603 0.030125 0.33161 0.00393  0.992
## Residuals 168   15.2620 0.090846         0.99607       
## Total     170   15.3223                  1.00000
#            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# Area        2    0.0603 0.030125 0.33161 0.00393  0.992
# Residuals 168   15.2620 0.090846         0.99607       
# Total     170   15.3223                  1.00000 


set.seed(30)
adonis(mData.Polyps123.dist~Area*ATTRIBUTE_Colony_number, data=mData.Polyps123.sd)
## 
## Call:
## adonis(formula = mData.Polyps123.dist ~ Area * ATTRIBUTE_Colony_number,      data = mData.Polyps123.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                               Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)    
## Area                           2    0.0603 0.03013  0.9495 0.00393  0.466    
## ATTRIBUTE_Colony_number       18   10.7537 0.59743 18.8308 0.70183  0.001 ***
## Area:ATTRIBUTE_Colony_number  36    0.8916 0.02477  0.7806 0.05819  0.986    
## Residuals                    114    3.6168 0.03173         0.23605           
## Total                        170   15.3223                 1.00000           
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#                               Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)    
# Area                           2    0.0603 0.03013  0.9495 0.00393  0.460    
# ATTRIBUTE_Colony_number       18   10.7537 0.59743 18.8308 0.70183  0.001 ***
# Area:ATTRIBUTE_Colony_number  36    0.8916 0.02477  0.7806 0.05819  0.983    
# Residuals                    114    3.6168 0.03173         0.23605           
# Total                        170   15.3223                 1.00000         


#Plot by Colony number (see that still cluster by colony)
BetweenPoly123_plot<-ggplot(mData.Polyps123.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Colony_number), size = 4) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Polyps 1-3") +
  theme_classic();BetweenPoly123_plot

#Plot by Polyp number (see that no cluster)
BetweenPoly123_plot2<-ggplot(mData.Polyps123.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = Area), size = 4) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Polyps 1-3 by polyp#") +
  theme_classic();BetweenPoly123_plot2

Between Branches by individual colony

#Between Branches by colony ###########################



####### colony 945  ####### 
mData.Branch945<-subset(mData, ATTRIBUTE_Colony_number=="945") 
#subset data
mData.Branch945.sd<-mData.Branch945[,1:11]
# Bray-Curtis distance 
mData.Branch945.dist <- vegdist(mData.Branch945[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch945.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch945.dist.sd<- inner_join(rownames_to_column(mData.Branch945.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch945.dist~Area, data=mData.Branch945.sd)
## 
## Call:
## adonis(formula = mData.Branch945.dist ~ Area, data = mData.Branch945.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##           Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
## Area       5   0.16096 0.032193 0.96577 0.28694  0.505
## Residuals 12   0.40001 0.033334         0.71306       
## Total     17   0.56097                  1.00000
#            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# Area       5   0.16096 0.032193 0.96577 0.28694  0.499
# Residuals 12   0.40001 0.033334         0.71306       
# Total     17   0.56097                  1.00000    

#Plot by Colony number (see that still cluster by colony)
Branch945_plot<-ggplot(mData.Branch945.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size = 2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 945") +
  theme_classic();Branch945_plot

####### colony 957  ####### 
mData.Branch957<-subset(mData, ATTRIBUTE_Colony_number=="957") 
#subset data
mData.Branch957.sd<-mData.Branch957[,1:11]
# Bray-Curtis distance 
mData.Branch957.dist <- vegdist(mData.Branch957[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch957.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch957.dist.sd<- inner_join(rownames_to_column(mData.Branch957.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch957.dist~Area, data=mData.Branch957.sd)
## 
## Call:
## adonis(formula = mData.Branch957.dist ~ Area, data = mData.Branch957.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##           Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
## Area       5  0.084667 0.016933  1.1214 0.31845  0.303
## Residuals 12  0.181202 0.015100         0.68155       
## Total     17  0.265869                  1.00000
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# Area       5  0.084667 0.016933  1.1214 0.31845  0.303
# Residuals 12  0.181202 0.015100         0.68155       
# Total     17  0.265869                  1.00000       

#Plot by Colony number (see that still cluster by colony)
Branch957_plot<-ggplot(mData.Branch957.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size = 2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 957") +
  theme_classic();Branch957_plot

####### colony 959  ####### 
mData.Branch959<-subset(mData, ATTRIBUTE_Colony_number=="959") 
#subset data
mData.Branch959.sd<-mData.Branch959[,1:11]
# Bray-Curtis distance 
mData.Branch959.dist <- vegdist(mData.Branch959[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch959.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch959.dist.sd<- inner_join(rownames_to_column(mData.Branch959.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch959.dist~Area, data=mData.Branch959.sd)
## 
## Call:
## adonis(formula = mData.Branch959.dist ~ Area, data = mData.Branch959.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##           Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
## Area       5  0.071079 0.014216  1.0094 0.29607  0.464
## Residuals 12  0.168995 0.014083         0.70393       
## Total     17  0.240074                  1.00000
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# Area       5  0.084667 0.016933  1.1214 0.31845  0.303
# Residuals 12  0.181202 0.015100         0.68155       
# Total     17  0.265869                  1.00000       

#Plot by Colony number (see that still cluster by colony)
Branch959_plot<-ggplot(mData.Branch959.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size = 2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 959") +
  theme_classic();Branch959_plot

####### colony 960  ####### 
mData.Branch960<-subset(mData, ATTRIBUTE_Colony_number=="960") 
#subset data
mData.Branch960.sd<-mData.Branch960[,1:11]
# Bray-Curtis distance 
mData.Branch960.dist <- vegdist(mData.Branch960[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch960.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch960.dist.sd<- inner_join(rownames_to_column(mData.Branch960.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch960.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch960.sd)
## 
## Call:
## adonis(formula = mData.Branch960.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch960.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
## ATTRIBUTE_Branch_Letter  2   0.05525 0.027625  1.4696 0.16384  0.164
## Residuals               15   0.28196 0.018798         0.83616       
## Total                   17   0.33721                  1.00000
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2   0.05525 0.027625  1.4696 0.16384  0.164
# Residuals               15   0.28196 0.018798         0.83616       
# Total                   17   0.33721                  1.00000          

#Plot by Colony number (see that still cluster by colony)
Branch960_plot<-ggplot(mData.Branch960.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size = 2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 960") +
  theme_classic();Branch960_plot

####### colony 961  Sig####### 
mData.Branch961<-subset(mData, ATTRIBUTE_Colony_number=="961") 
#subset data
mData.Branch961.sd<-mData.Branch961[,1:11]
# Bray-Curtis distance 
mData.Branch961.dist <- vegdist(mData.Branch961[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch961.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch961.dist.sd<- inner_join(rownames_to_column(mData.Branch961.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch961.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch961.sd)
## 
## Call:
## adonis(formula = mData.Branch961.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch961.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)  
## ATTRIBUTE_Branch_Letter  2   0.12052 0.060262  2.7776 0.27026  0.022 *
## Residuals               15   0.32543 0.021695         0.72974         
## Total                   17   0.44595                  1.00000         
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#           Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2   0.12052 0.060262  2.7776 0.27026   0.03 *
# Residuals               15   0.32543 0.021695         0.72974         
# Total                   17   0.44595                  1.00000              

#Plot by Colony number (see that still cluster by colony)
Branch961_plot<-ggplot(mData.Branch961.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 961") +
  theme_classic();Branch961_plot

####### colony 962 Significant ####### 
mData.Branch962<-subset(mData, ATTRIBUTE_Colony_number=="962") 
#subset data
mData.Branch962.sd<-mData.Branch962[,1:11]
# Bray-Curtis distance 
mData.Branch962.dist <- vegdist(mData.Branch962[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch962.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch962.dist.sd<- inner_join(rownames_to_column(mData.Branch962.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch962.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch962.sd)
## 
## Call:
## adonis(formula = mData.Branch962.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch962.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)  
## ATTRIBUTE_Branch_Letter  2   0.23235 0.11618  2.3623 0.23953  0.011 *
## Residuals               15   0.73770 0.04918         0.76047         
## Total                   17   0.97005                 1.00000         
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# ATTRIBUTE_Branch_Letter  2   0.23235 0.11618  2.3623 0.23953  0.016 *
# Residuals               15   0.73770 0.04918         0.76047         
# Total                   17   0.97005                 1.00000         

#Plot by Colony number (see that still cluster by colony)
Branch962_plot<-ggplot(mData.Branch962.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 962") +
  theme_classic();Branch962_plot

####### colony 963 Sig ####### 
mData.Branch963<-subset(mData, ATTRIBUTE_Colony_number=="963") 
#subset data
mData.Branch963.sd<-mData.Branch963[,1:11]
# Bray-Curtis distance 
mData.Branch963.dist <- vegdist(mData.Branch963[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch963.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch963.dist.sd<- inner_join(rownames_to_column(mData.Branch963.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch963.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch963.sd)
## 
## Call:
## adonis(formula = mData.Branch963.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch963.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)   
## ATTRIBUTE_Branch_Letter  2  0.072242 0.036121  4.0202 0.34897  0.004 **
## Residuals               15  0.134771 0.008985         0.65103          
## Total                   17  0.207013                  1.00000          
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2  0.072242 0.036121  4.0202 0.34897  0.004 **
# Residuals               15  0.134771 0.008985         0.65103          
# Total                   17  0.207013                  1.00000          

#Plot by Colony number (see that still cluster by colony)
Branch963_plot<-ggplot(mData.Branch963.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 963") +
  theme_classic();Branch963_plot

####### colony 964  ####### 
mData.Branch964<-subset(mData, ATTRIBUTE_Colony_number=="964") 
#subset data
mData.Branch964.sd<-mData.Branch964[,1:11]
# Bray-Curtis distance 
mData.Branch964.dist <- vegdist(mData.Branch964[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch964.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch964.dist.sd<- inner_join(rownames_to_column(mData.Branch964.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch964.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch964.sd)
## 
## Call:
## adonis(formula = mData.Branch964.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch964.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
## ATTRIBUTE_Branch_Letter  2   0.06878 0.034389 0.56486 0.07004  0.901
## Residuals               15   0.91322 0.060881         0.92996       
## Total                   17   0.98200                  1.00000
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2   0.06878 0.034389 0.56486 0.07004  0.901
# Residuals               15   0.91322 0.060881         0.92996       
# Total                   17   0.98200                  1.00000       

#Plot by Colony number (see that still cluster by colony)
Branch964_plot<-ggplot(mData.Branch964.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 964") +
  theme_classic();Branch964_plot

####### colony 965  ####### 
mData.Branch965<-subset(mData, ATTRIBUTE_Colony_number=="965") 
#subset data
mData.Branch965.sd<-mData.Branch965[,1:11]
# Bray-Curtis distance 
mData.Branch965.dist <- vegdist(mData.Branch965[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch965.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch965.dist.sd<- inner_join(rownames_to_column(mData.Branch965.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch965.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch965.sd)
## 
## Call:
## adonis(formula = mData.Branch965.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch965.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)  
## ATTRIBUTE_Branch_Letter  2  0.035052 0.017526  1.6975 0.18456  0.096 .
## Residuals               15  0.154870 0.010325         0.81544         
## Total                   17  0.189922                  1.00000         
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# # #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2  0.035052 0.017526  1.6975 0.18456  0.096 .
# Residuals               15  0.154870 0.010325         0.81544         
# Total                   17  0.189922                  1.00000         

#Plot by Colony number (see that still cluster by colony)
Branch965_plot<-ggplot(mData.Branch965.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 965") +
  theme_classic();Branch965_plot

####### colony 966  ####### 
mData.Branch966<-subset(mData, ATTRIBUTE_Colony_number=="966") 
#subset data
mData.Branch966.sd<-mData.Branch966[,1:11]
# Bray-Curtis distance 
mData.Branch966.dist <- vegdist(mData.Branch966[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch966.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch966.dist.sd<- inner_join(rownames_to_column(mData.Branch966.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch966.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch966.sd)
## 
## Call:
## adonis(formula = mData.Branch966.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch966.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)  
## ATTRIBUTE_Branch_Letter  2   0.09030 0.045150  1.6735 0.18243  0.063 .
## Residuals               15   0.40469 0.026979         0.81757         
## Total                   17   0.49499                  1.00000         
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2   0.09030 0.045150  1.6735 0.18243  0.063 .
# Residuals               15   0.40469 0.026979         0.81757         
# Total                   17   0.49499                  1.00000  

#Plot by Colony number (see that still cluster by colony)
Branch966_plot<-ggplot(mData.Branch966.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 966") +
  theme_classic();Branch966_plot

####### colony 967 Sig  ####### 
mData.Branch967<-subset(mData, ATTRIBUTE_Colony_number=="967") 
#subset data
mData.Branch967.sd<-mData.Branch967[,1:11]
# Bray-Curtis distance 
mData.Branch967.dist <- vegdist(mData.Branch967[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch967.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch967.dist.sd<- inner_join(rownames_to_column(mData.Branch967.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch967.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch967.sd)
## 
## Call:
## adonis(formula = mData.Branch967.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch967.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)   
## ATTRIBUTE_Branch_Letter  2  0.063923 0.031961  2.1131 0.21981  0.007 **
## Residuals               15  0.226880 0.015125         0.78019          
## Total                   17  0.290802                  1.00000          
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2  0.063923 0.031961  2.1131 0.21981  0.007 **
# Residuals               15  0.226880 0.015125         0.78019          
# Total                   17  0.290802                  1.00000 

#Plot by Colony number (see that still cluster by colony)
Branch967_plot<-ggplot(mData.Branch967.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 967") +
  theme_classic();Branch967_plot

####### colony 968  Sig #######  
mData.Branch968<-subset(mData, ATTRIBUTE_Colony_number=="968") 
#subset data
mData.Branch968.sd<-mData.Branch968[,1:11]
# Bray-Curtis distance 
mData.Branch968.dist <- vegdist(mData.Branch968[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch968.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch968.dist.sd<- inner_join(rownames_to_column(mData.Branch968.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch968.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch968.sd)
## 
## Call:
## adonis(formula = mData.Branch968.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch968.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model     R2 Pr(>F)  
## ATTRIBUTE_Branch_Letter  2   0.13431 0.067156  1.9566 0.2069   0.04 *
## Residuals               15   0.51484 0.034323         0.7931         
## Total                   17   0.64915                  1.0000         
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# # #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2   0.13431 0.067156  1.9566 0.2069   0.04 *
# Residuals               15   0.51484 0.034323         0.7931         
# Total                   17   0.64915                  1.0000    

#Plot by Colony number (see that still cluster by colony)
Branch968_plot<-ggplot(mData.Branch968.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 968") +
  theme_classic();Branch968_plot

####### colony 969  ####### 
mData.Branch969<-subset(mData, ATTRIBUTE_Colony_number=="969") 
#subset data
mData.Branch969.sd<-mData.Branch969[,1:11]
# Bray-Curtis distance 
mData.Branch969.dist <- vegdist(mData.Branch969[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch969.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch969.dist.sd<- inner_join(rownames_to_column(mData.Branch969.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch969.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch969.sd)
## 
## Call:
## adonis(formula = mData.Branch969.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch969.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
## ATTRIBUTE_Branch_Letter  2   0.05642 0.028210  1.1902 0.13695  0.276
## Residuals               15   0.35554 0.023703         0.86305       
## Total                   17   0.41196                  1.00000
# # #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2   0.05642 0.028210  1.1902 0.13695  0.276
# Residuals               15   0.35554 0.023703         0.86305       
# Total                   17   0.41196                  1.00000       

#Plot by Colony number (see that still cluster by colony)
Branch969_plot<-ggplot(mData.Branch969.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 969") +
  theme_classic();Branch969_plot

####### colony 971  ####### 
mData.Branch971<-subset(mData, ATTRIBUTE_Colony_number=="971") 
#subset data
mData.Branch971.sd<-mData.Branch971[,1:11]
# Bray-Curtis distance 
mData.Branch971.dist <- vegdist(mData.Branch971[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch971.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch971.dist.sd<- inner_join(rownames_to_column(mData.Branch971.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch971.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch971.sd)
## 
## Call:
## adonis(formula = mData.Branch971.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch971.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model     R2 Pr(>F)
## ATTRIBUTE_Branch_Letter  2   0.07725 0.038623  1.1665 0.1346  0.339
## Residuals               15   0.49665 0.033110         0.8654       
## Total                   17   0.57390                  1.0000
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2   0.07725 0.038623  1.1665 0.1346  0.339
# Residuals               15   0.49665 0.033110         0.8654       
# Total                   17   0.57390                  1.0000     

#Plot by Colony number (see that still cluster by colony)
Branch971_plot<-ggplot(mData.Branch971.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 971") +
  theme_classic();Branch971_plot

####### colony 974 Sig  ####### 
mData.Branch974<-subset(mData, ATTRIBUTE_Colony_number=="974") 
#subset data
mData.Branch974.sd<-mData.Branch974[,1:11]
# Bray-Curtis distance 
mData.Branch974.dist <- vegdist(mData.Branch974[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch974.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch974.dist.sd<- inner_join(rownames_to_column(mData.Branch974.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch974.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch974.sd)
## 
## Call:
## adonis(formula = mData.Branch974.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch974.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)    
## ATTRIBUTE_Branch_Letter  2  0.065853 0.032926  3.0197 0.28705  0.001 ***
## Residuals               15  0.163557 0.010904         0.71295           
## Total                   17  0.229409                  1.00000           
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2  0.065853 0.032926  3.0197 0.28705  0.001 ***
# Residuals               15  0.163557 0.010904         0.71295           
# Total                   17  0.229409                  1.00000          

#Plot by Colony number (see that still cluster by colony)
Branch974_plot<-ggplot(mData.Branch974.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 974") +
  theme_classic();Branch974_plot

####### colony 976  ####### 
mData.Branch976<-subset(mData, ATTRIBUTE_Colony_number=="976") 
#subset data
mData.Branch976.sd<-mData.Branch976[,1:11]
# Bray-Curtis distance 
mData.Branch976.dist <- vegdist(mData.Branch976[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch976.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch976.dist.sd<- inner_join(rownames_to_column(mData.Branch976.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch976.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch976.sd)
## 
## Call:
## adonis(formula = mData.Branch976.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch976.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
## ATTRIBUTE_Branch_Letter  2   0.19834 0.099168  1.6206 0.17769  0.128
## Residuals               15   0.91786 0.061191         0.82231       
## Total                   17   1.11620                  1.00000
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2   0.19834 0.099168  1.6206 0.17769  0.128
# Residuals               15   0.91786 0.061191         0.82231       
# Total                   17   1.11620                  1.00000       

#Plot by Colony number (see that still cluster by colony)
Branch976_plot<-ggplot(mData.Branch976.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 976") +
  theme_classic();Branch976_plot

####### colony 978  ####### 
mData.Branch978<-subset(mData, ATTRIBUTE_Colony_number=="978") 
#subset data
mData.Branch978.sd<-mData.Branch978[,1:11]
# Bray-Curtis distance 
mData.Branch978.dist <- vegdist(mData.Branch978[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch978.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch978.dist.sd<- inner_join(rownames_to_column(mData.Branch978.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch978.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch978.sd)
## 
## Call:
## adonis(formula = mData.Branch978.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch978.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
## ATTRIBUTE_Branch_Letter  2   0.05551 0.027757  1.2815 0.14593   0.27
## Residuals               15   0.32490 0.021660         0.85407       
## Total                   17   0.38042                  1.00000
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2   0.05551 0.027757  1.2815 0.14593   0.27
# Residuals               15   0.32490 0.021660         0.85407       
# Total                   17   0.38042                  1.00000    

#Plot by Colony number (see that still cluster by colony)
Branch978_plot<-ggplot(mData.Branch978.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 978") +
  theme_classic();Branch978_plot

####### colony 983  ####### 
mData.Branch983<-subset(mData, ATTRIBUTE_Colony_number=="983") 
#subset data
mData.Branch983.sd<-mData.Branch983[,1:11]
# Bray-Curtis distance 
mData.Branch983.dist <- vegdist(mData.Branch983[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch983.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch983.dist.sd<- inner_join(rownames_to_column(mData.Branch983.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch983.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch983.sd)
## 
## Call:
## adonis(formula = mData.Branch983.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch983.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
## ATTRIBUTE_Branch_Letter  2   0.21713 0.108565  1.0892 0.12681  0.367
## Residuals               15   1.49516 0.099677         0.87319       
## Total                   17   1.71229                  1.00000
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2   0.21713 0.108565  1.0892 0.12681  0.367
# Residuals               15   1.49516 0.099677         0.87319       
# Total                   17   1.71229                  1.00000

#Plot by Colony number (see that still cluster by colony)
Branch983_plot<-ggplot(mData.Branch983.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 983") +
  theme_classic();Branch983_plot

####### colony 984  ####### 
mData.Branch984<-subset(mData, ATTRIBUTE_Colony_number=="984") 
#subset data
mData.Branch984.sd<-mData.Branch984[,1:11]
# Bray-Curtis distance 
mData.Branch984.dist <- vegdist(mData.Branch984[,12:566],  method = "bray")

PCOA <- pcoa(mData.Branch984.dist) #pcoa
barplot(PCOA$values$Relative_eig[1:10]) # plot the eigenvalues 

biplot.pcoa(PCOA) #plot

PCOAaxes <- PCOA$vectors[,c(1,2)] #for visualization only

 mData.Branch984.dist.sd<- inner_join(rownames_to_column(mData.Branch984.sd), rownames_to_column(data.frame(PCOAaxes)), type = "right", by = "rowname") #merge PCOAaxes and metadata


set.seed(30)
adonis(mData.Branch984.dist~ATTRIBUTE_Branch_Letter, data=mData.Branch984.sd)
## 
## Call:
## adonis(formula = mData.Branch984.dist ~ ATTRIBUTE_Branch_Letter,      data = mData.Branch984.sd) 
## 
## Permutation: free
## Number of permutations: 999
## 
## Terms added sequentially (first to last)
## 
##                         Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)  
## ATTRIBUTE_Branch_Letter  2  0.044803 0.022402  1.7273 0.18719  0.091 .
## Residuals               15  0.194538 0.012969         0.81281         
## Total                   17  0.239341                  1.00000         
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# #            Df SumsOfSqs  MeanSqs F.Model      R2 Pr(>F)
# ATTRIBUTE_Branch_Letter  2  0.044803 0.022402  1.7273 0.18719  0.091 .
# Residuals               15  0.194538 0.012969         0.81281         
# Total                   17  0.239341                  1.00000     

#Plot by Colony number (see that still cluster by colony)
Branch984_plot<-ggplot(mData.Branch984.dist.sd, aes(x = Axis.1, y = Axis.2)) + 
  geom_point(aes(colour = ATTRIBUTE_Branch_Letter), size=2) +
  #scale_color_manual(values=Sp.colors)+
  #geom_text(label = rownames(scores), nudge_x = 0.05, nudge_y = 0.05,check_overlap = T) +
 # stat_ellipse(aes(x = Axis.1, y = Axis.2, colour = ATTRIBUTE_Colony_number), linetype = 2) +
  ggtitle("PCoA Between Branches 984") +
  theme_classic();Branch984_plot

Plot all Colonies in same plot

###### All plots together
Branch945_plot<-Branch945_plot+ theme(legend.position = "none") #remove legend
Branch957_plot<-Branch957_plot+ theme(legend.position = "none") #remove legend
Branch959_plot<-Branch959_plot+ theme(legend.position = "none") #remove legend
Branch960_plot<-Branch960_plot+ theme(legend.position = "none") #remove legend
Branch961_plot<-Branch961_plot+ theme(legend.position = "none") #remove legend
Branch962_plot<-Branch962_plot+ theme(legend.position = "none") #remove legend
Branch963_plot<-Branch963_plot+ theme(legend.position = "none") #remove legend
Branch964_plot<-Branch964_plot+ theme(legend.position = "none") #remove legend
Branch965_plot<-Branch965_plot+ theme(legend.position = "none") #remove legend
Branch966_plot<-Branch966_plot+ theme(legend.position = "none") #remove legend
Branch967_plot<-Branch967_plot+ theme(legend.position = "none") #remove legend
Branch968_plot<-Branch968_plot+ theme(legend.position = "none") #remove legend
Branch969_plot<-Branch969_plot+ theme(legend.position = "none") #remove legend
Branch971_plot<-Branch971_plot+ theme(legend.position = "none") #remove legend
Branch974_plot<-Branch974_plot+ theme(legend.position = "none") #remove legend
Branch976_plot<-Branch976_plot+ theme(legend.position = "none") #remove legend
Branch978_plot<-Branch978_plot+ theme(legend.position = "none") #remove legend
Branch983_plot<-Branch983_plot+ theme(legend.position = "none") #remove legend
 Branch984_plot<-Branch984_plot+ theme(legend.position = "none") #remove legend



grid.arrange(Branch945_plot, Branch957_plot, Branch959_plot,Branch960_plot, 
             Branch961_plot,Branch962_plot,Branch963_plot,Branch964_plot,
             Branch965_plot,Branch966_plot,Branch967_plot,Branch968_plot,
             Branch969_plot,Branch971_plot,Branch974_plot,Branch976_plot,
             Branch978_plot,Branch983_plot,Branch984_plot,nrow = 5)